package com.gitee.cirnochat.file.controller;

import com.gitee.cirnochat.common.annotation.AuthCheck;
import com.gitee.cirnochat.common.model.vo.resp.Result;
import com.gitee.cirnochat.file.model.vo.resp.FileUploadResponse;
import com.gitee.cirnochat.file.service.FileManager;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@Tag(name = "文件上传相关接口", description = "文件上传相关API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/file")
public class FileController {
    private final FileManager fileManager;

    @Operation(summary = "上传文件", description = "上传文件")
    @ApiResponse(
            responseCode = "200",
            description = "成功"
    )
    @AuthCheck
    @PostMapping(value = "/upload", consumes = "multipart/form-data")
    @Parameter(name = "Authorization", description = "认证信息", required = true , in = ParameterIn.HEADER)
    @Parameter(name = "X-Device-Id", description = "设备ID", required = true , in = ParameterIn.HEADER)
    public Result<FileUploadResponse> uploadFile(@RequestPart("file") MultipartFile file) {
        return Result.success(fileManager.uploadFile(file));
    }


}
